package com.qfedu.course.service.impl;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.C;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.course.entity.Course;
import com.qfedu.course.mapper.CourseMapper;
import com.qfedu.course.service.ICourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.QfConstant;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.aspectj.weaver.AjAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 课程管理 服务实现类
 * </p>
 *
 * @author zhangsan
 * @since 2023-03-02
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {



    @Autowired
    CourseMapper courseMapper;
    @Override
    public List<Course> getlist() {
        return courseMapper.getlist();
    }

    @Override
    public AjaxResult addCourse(Course course) {
        QueryWrapper<Course> qw = new QueryWrapper<>();
        qw.lambda().eq(Course::getName,course.getName());
        Course course1 = getOne(qw);
        if (course1!=null){
            return AjaxResult.error("重复添加");
        }
        course.setCreateTime(LocalDateTime.now());
        return save(course)? AjaxResult.success("添加成功") : AjaxResult.error("添加失败");
    }

    @Override
    public AjaxResult DeleteCourse(Long[] courseids) {
        boolean b=  courseMapper.DeleteCourse(courseids);
        return b ? AjaxResult.success("删除成功"): AjaxResult.error("删除失败");
    }

    @Override
    public AjaxResult Deleteuser(String add) {
        return null;
    }
}
